#include <iostream>
#include <math.h>

void countMeanVariance(double array[], int length, double &mean, double &variance){
    double sum = 0.0;
    for (int i = 0; i < length; ++i){
        sum += array[i];
    }
    mean = sum / length;
    double dsum = 0.0;
    for (int i = 0; i < length; ++i){
        dsum += pow(array[i] - mean, 2);
    }
    variance = dsum / length;
}

int main(int argc, char *argv[])
{
    double array[10];
    int length = sizeof(array) / sizeof(array[0]);
    for (auto i = 0; i < length; ++i){
        array[i] = i;
    }
    double mean = 0.0;
    double variance = 0.0;
    countMeanVariance(array, length, mean, variance);

    std::cout << "array is "<< std::endl;
    for (int i = 0; i < length; ++i){
        std::cout << array[i] << " ";
    }
    std::cout << std::endl;
    std::cout << "mean is " << mean << std::endl;
    std::cout << "variance is " << variance << std::endl;

    return 0;
}
